cmake_minimum_required(VERSION 3.9)

set(COAP_FILES
        CMCoapBroadcast.cpp
        CMCoapBroadcast.h
        CMCoapServer.cpp
        CMCoapServer.h
        )

set(MQTT_FILES
        CMMqttBase.cpp
        CMMqttBase.h
        CMMqttMosquitto.cpp
        CMMqttMosquitto.h
        )

set(NET_FILES
        CMHttpEx.cpp
        CMHttpEx.h
        )

set(NET_CURL_FILES
        CMHttpExCurl.cpp
        CMHttpExCurl.h
        )

include_directories(http)
include_directories(connect)
set(HTTP_FILES
        http/cm_http.c
        http/cm_http.h
        http/cm_http_download.c
        http/cm_http_download.h
        http/cm_http_upload.c
        http/cm_http_upload.h
        http/http_parser.c
        http/http_parser.h
        http/cm_conn_ws.c
        http/cm_conn_ws.h
        )

set(CONNECT_FILES
        connect/cm_broadcast.c
        connect/cm_broadcast.h
        connect/cm_conn_tcp.c
        connect/cm_conn_tcp.h
        connect/cm_conn_udp.c
        connect/cm_conn_udp.h
        connect/cm_unixsocket.c
        connect/cm_unixsocket.h
        )

add_library(net
        ${CONNECT_FILES}
        ${HTTP_FILES}
        )

if (WITH_COAP)
add_executable(cm_coap_broad_test
        cm_coap_broad_test.cpp
        ${COAP_FILES}
        )

add_executable(cm_coap_test
        cm_coap_test.cpp
        ${COAP_FILES}
        )
endif()

if (WITH_MQTT)
    add_executable(cm_snet_test
            cm_snet_test.cpp
            ${MQTT_FILES}
            )
    target_link_libraries(cm_snet_test
            mosquitto
            utils
    )
endif()

if (WITH_HTTP)
    add_executable(cm_net_test
            cm_net_test.cpp
            ${NET_FILES}
            ${NET_CURL_FILES}
            )
endif()

add_executable(cm_broadcast_test
        connect/cm_broadcast_test.c
        ../utils/cm_print.c
        ../utils/cm_print.h
        ../utils/cm_utils.c
        ../utils/cm_utils.h
        ${CONNECT_FILES}
        )

target_link_libraries(cm_broadcast_test
        pthread)

add_executable(cm_http_upload_test
        http/cm_http_upload_test.c
        ../crypto/cm_base64.c
        ../crypto/cm_base64.h
        ../utils/cm_utils.c
        ../utils/cm_utils.h
        ${HTTP_FILES}
        ${CONNECT_FILES}
        )

target_link_libraries(cm_http_upload_test
        utils
        pthread)
